<template>
    <div class="shopcar">
        <div class="mui-card" v-for="item in goodsList" :key="item.id">
            <div class="mui-card-content">
                <div class="mui-card-content-inner">
                    <mt-switch></mt-switch>
                    <img :src="item.thumb_path" alt="">
                    <div class="info">
                        <h1>{{item.title}}</h1>
                        <div class="options">
                            <span class="price">￥{{item.sell_price}}</span>
                             <div class="mui-numbox" data-numbox-step='1' data-numbox-min='1'>
                                <button class="mui-btn mui-btn-numbox-minus" type="button">-</button>
                                <input id="test" class="mui-input-numbox" type="number" :value="$store.getters.getGoodsCount[item.id]" />
                                <button class="mui-btn mui-btn-numbox-plus" type="button">+</button>
                            </div>
                            <a href="">删除 </a>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <div class="mui-card">
            <div class="mui-card-content">
                <div class="mui-card-content-inner">
                    
                </div>
            </div>
        </div>
    </div>
</template>

<script>
    import { Toast } from 'mint-ui'
    //导入mui.js
    import mui from '../../lib/mui/js/mui.min.js'
    export default {
        data(){
            return {
                goodsList:[]
            }
        },
        created(){
            this.getShopCarList()
        },
        mounted(){
            this.numbox = mui('.mui-numbox').numbox()
        },
        methods:{
            getShopCarList(){
                let ids = []
                this.$store.state.car.forEach(item => ids.push(item.id));
                //购物车内没有商品，不用请求数据
                if(ids.length <= 0){
                    return;
                }
                this.$http.get('api/goods/getshopcarlist/' + ids.join(',')).then(result => {
                    if(result.body.status == 0){
                        this.goodsList = result.body.message
                    }else{
                        Toast('获取购物车数据失败')
                    }
                })
            }
        }
    }
</script>

<style lang="sass" scoped>
    .shopcar{
        overflow:hidden;
        background-color:#eee;

        .mui-card-content-inner{
            display:flex;
            align-items:center;

            img{
                width:60px;
                height:60px;
            }

            h1{
                font-size:13px;
            }
            .info{
                .options{
                    margin-top:5px;
                    .price{
                        color:red;
                        font-weight:bold;
                    }
                }
                
            }
        }
    }
</style>
